package wrs.hcs.functions;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

public class Hcs_Nursing {

	public void validate(WebDriver driver, String pin){
		
		driver.manage().window().maximize();
		driver.findElement(By.xpath("//a[@href='/nursing/general-units/generalUnitsHome.html']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='criteria']")).sendKeys(pin);
		driver.findElement(By.xpath("//input[@name='search']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		Select action = new Select(driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[6]/select")));
		action.selectByVisibleText("Package Management");
		driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[7]/input")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//driver.findElement(By.xpath("//input[@id='showDoctorFinder']")).click();
		//driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		//driver.findElement(By.xpath("//input[@value='Search']")).click();
		//driver.findElement(By.xpath("//tbody[@id='finder_table_body']/tr[1]/td[1]/div")).click();
		//driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//input[@id='add']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='validate']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@value='OK']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		System.out.println("Package Validated.");
		
	}
	
	public void discharge(WebDriver driver, String pin){
		
		driver.manage().window().maximize();
		driver.findElement(By.xpath("//a[@href='/nursing/general-units/generalUnitsHome.html']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='criteria']")).sendKeys(pin);
		driver.findElement(By.xpath("//input[@name='search']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		Select action = new Select(driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[6]/select")));
		action.selectByVisibleText("Discharge Instructions ");
		driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[7]/input")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//input[@id='txtFinalDiagnosis']")).sendKeys("Frequent Fever");
		driver.findElement(By.xpath("//input[@value='Add']")).click();
		Select disposition = new Select(driver.findElement(By.xpath("//select[@id='diagnosisForm.disposition']")));
		disposition.selectByVisibleText("RECOVERED");		
		
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='btnSave']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		System.out.println("Discharge Instructions Completed.");
		
	}
	
	public void pf(WebDriver driver, String pin){
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//a[@href='/nursing/general-units/generalUnitsHome.html']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='criteria']")).sendKeys(pin);
		driver.findElement(By.xpath("//input[@name='search']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		Select action = new Select(driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[6]/select")));
		action.selectByVisibleText("Doctor and PF Amount");
		driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[7]/input")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//tbody[@id='admissionDoctorBeanRows']/tr/td[6]/input[2]")).click();
		driver.findElement(By.xpath("//input[@id='btnAddPf']")).click();
		String input = driver.findElement(By.xpath("//div[@id='maximumComplementaryText']")).getText();
		input = input.replaceAll("\\s", "");
		input = input.replaceAll(",", "");
		System.out.println(input);
		WebElement pfAmount = driver.findElement(By.xpath("//input[@id='pfAmountInput']"));
		pfAmount.clear();
		pfAmount.sendKeys(input);
		Select pfType = new Select(driver.findElement(By.xpath("//select[@id='pfTypeCode']")));
		pfType.selectByVisibleText("PF INCLUSIVE OF PACKAGE");
		driver.findElement(By.xpath("//input[@id='btnAddPf']")).click();
		driver.findElement(By.xpath("//input[@value='Save']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//input[@id='dischargeAction']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//div[@id='dischargeForm']/input[@value='Discharge']")).click();
		System.out.println("Discharged on Nursing Unit");
	}
	
	public void gatepass(WebDriver driver, String pin){
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//a[@href='/nursing/general-units/generalUnitsHome.html']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='criteria']")).sendKeys(pin);
		driver.findElement(By.xpath("//input[@name='search']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@value='Print Gate Pass']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		Select gatepass = new Select(driver.findElement(By.xpath("//select[@id='roomBedStatusOptions']")));
		gatepass.selectByVisibleText("GENERAL CLEANING");
		driver.findElement(By.xpath("//input[@id='submitPhysOut']")).click();
		
		System.out.println("Gate Pass Printed.");
		
	}
	
	public void admit(WebDriver driver, String pin){
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//a[@href='/nursing/general-units/generalUnitsHome.html']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='criteria']")).sendKeys(pin);
		driver.findElement(By.xpath("//input[@name='search']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		Select action = new Select(driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[6]/select")));
		action.selectByVisibleText("Doctor and PF Amount");
		driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[7]/input")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//tbody[@id='admissionDoctorBeanRows']/tr/td[6]/input[2]")).click();
		driver.findElement(By.xpath("//input[@id='btnAddPf']")).click();
		WebElement pfAmount = driver.findElement(By.xpath("//input[@id='pfAmountInput']"));
		pfAmount.clear();
		pfAmount.sendKeys("100");
		Select pfType = new Select(driver.findElement(By.xpath("//select[@id='pfTypeCode']")));
		pfType.selectByVisibleText("COLLECT");
		driver.findElement(By.xpath("//input[@id='btnAddPf']")).click();
		driver.findElement(By.xpath("//input[@value='Save']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//input[@id='dischargeAction']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		driver.findElement(By.xpath("//div[@id='dischargeForm']/input[@value='Discharge']")).click();
		System.out.println("Discharged on Nursing Unit");
	}
	
}
